<!DOCTYPE html>
<html lang="en">

<head>
    <title></title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="css/style.css" rel="stylesheet">
    <style>
        :root {
            font-size: 10px;
        }

        * {
            margin: 0;
            padding: 0;
            border: 0;
        }

        body {
            display: flex;
            align-items: center;
            justify-content: center;
            height: 80vh;
            width: 100vw;
        }

        .box {
            width: 300px;
            height: 200px;
            border: 2px solid green;
            position: relative;
            border-radius: 10%;

        }

        .warp {
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);

        }

        .time {
            font-size: 4em;
            margin-bottom: 20px;
            color: green;
        }

        .action {
            width: 100%;
            /* background-color: green; */

        }

        .action button {
            width: 100%;
            color: #fff;
            background-image: linear-gradient(#e66465, #9198e5);
            height: 30px;
            border-radius: 10%;
        }

        span:nth-child(odd) {
            color: pink;
        }
    </style>
</head>
<div class="box">
    <div class="warp">
        <div class="time">
            <span>00</span>
            <span>:</span>
            <span>00</span>
        </div>
        <div class="action"> <button>开始/结束</button></button></div>
    </div>
</div>
<button id="xq">按需导入模块</button>

<body>
    <script type="module">
        import { js as user } from '../js/模块化1.js';//按需导入
        import js from '../js/模块化1.js';//默认导出
        new user('.box');
    </script>
    <script>
        let module = (function () {
            const moduleLists = {};
            function define(name, moudles, action) {
                moudles.map((m, i) => {
                    moudles[i] = moduleLists[m];
                });
                //执行并保存模块
                moduleLists[name] = action.apply(null, moudles);
            }
            return { define };
        })();
        //声明模块不依赖其它模块
        module.define("hd", [], function () {
            return {
                show() {
                    console.log("hd module show");
                }
            };
        });

        //声明模块时依赖其它模块
        module.define("xj", ["hd"], function (hd) {
            hd.show();
        });
        //模块的动态加载
        document.querySelector('#xq').addEventListener('click', () => {
            import('../js/按需导入.js').then(() => {
                console.log('导入成功');
            }).catch(() => {
                console.log('导入失败');
            });
        })
    </script>
</body>

</html>